package com.lyf.controller.user;

import com.lyf.dto.OrdersCancelDTO;
import com.lyf.dto.OrdersPaymentDTO;
import com.lyf.dto.OrdersSubmitDTO;
import com.lyf.result.PageResult;
import com.lyf.result.Result;
import com.lyf.service.OrderService;
import com.lyf.vo.OrderDetailVO;
import com.lyf.vo.OrderPaymentVO;
import com.lyf.vo.OrderSubmitVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api("用户端订单接口管理")
@RequestMapping("/user/order")
@RestController("userOrderController")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("用户下单")
    @PostMapping("submit")
    public Result submitOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        log.info("用户下单：{}", ordersSubmitDTO);
        OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    @ApiOperation("订单支付")
    @PutMapping("payment")
    public Result payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO){
        log.info("订单支付：{}",ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO =  orderService.payment(ordersPaymentDTO);
        log.info("订单支付结果：{}",orderPaymentVO);
        return Result.success(orderPaymentVO);
    }

    @ApiOperation("查询历史订单")
    @GetMapping("historyOrders")
    public Result historyOrders(Integer page, Integer pageSize, Integer status){
        log.info("查询历史订单：{}",page,pageSize, status);
        PageResult pageResult = orderService.historyOrders(page,pageSize,status);
        return Result.success(pageResult);
    }

    @ApiOperation("查询订单详情")
    @GetMapping("orderDetail/{id}")
    public Result getOrderdetails(@PathVariable Long id){
        log.info("查询订单详情：{}",id);
        OrderDetailVO orderDetailVO = orderService.getOrderdetails(id);
        return Result.success(orderDetailVO);
    }

    @ApiOperation("取消订单")
    @PutMapping("cancel/{id}")
    public Result cancel(@PathVariable Long id){
        log.info("取消订单：{}",id);
        OrdersCancelDTO ordersCancelDTO = new OrdersCancelDTO();
        ordersCancelDTO.setId(id);
        ordersCancelDTO.setCancelReason("用户取消");
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    @ApiOperation("再来一单")
    @PostMapping("repetition/{id}")
    public Result repetition(@PathVariable Long id){
        log.info("再来一单：{}",id);
        orderService.repetition(id);
        return Result.success();
    }

    @ApiOperation("催单")
    @GetMapping("reminder/{id}")
    public Result reminder(@PathVariable Long id){
        log.info("催单：{}",id);
        orderService.reminder(id);
        return Result.success();
    }
}
